﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VoiceMessager.Stream;
using VoiceMessager.Stream.Cmd;

namespace VoiceMessager
{
	public static class Statics
	{
		public static string ByteArrayToString(byte[] bytes)
		{
			return string.Join(" ", bytes.Select(i => i.ToString("X2")));
		}

		public static byte[] GetEncodingBytes(CmdCommandParam param, string text)
		{
			switch (param)
			{
				case CmdCommandParam.Gbk:
					return Encoding.GetEncoding("GBK").GetBytes(text);
				case CmdCommandParam.Big5:
					return Encoding.GetEncoding("BIG5").GetBytes(text);
				case CmdCommandParam.UnicodeLe:
					return Encoding.Unicode.GetBytes(text);
				case CmdCommandParam.UnicodeBe:
					return Encoding.BigEndianUnicode.GetBytes(text);
				case CmdCommandParam.Gb2312:
				default:
					return Encoding.GetEncoding("GB2312").GetBytes(text);
			}
		}

		public static byte[] GetVerifyBytes(VerifyMethod verifyMethod, byte[] bytes)
		{
			switch (verifyMethod)
			{
				case VerifyMethod.None:
					return new byte[] { 0x12, 0x34 };
				case VerifyMethod.Xor:
					return new byte[] { 0x23, 0x45 };
				case VerifyMethod.Partity:
					return new byte[] { 0x34, 0x56 };
				case VerifyMethod.Crc:
					return new byte[] { 0x45, 0x67 };
				default:
					return new byte[] { 0x56, 0x78 };
			}
		}
	}
}
